package com.example.mydata.Exception;

import com.example.mydata.Vo.Book;
import com.example.mydata.Vo.BookStatus;
import com.example.mydata.Vo.User;

public class LibraryException extends RuntimeException{
    public enum ExceptionType {
        NO_STOCK,//("库存不足"),
        LIMIT_EXCEEDED,//("借书数量超限"),
        BOOK_UNAVAILABLE//("书籍不可用")
        // 可以继续添加其他异常类型
    }
    public LibraryException(String message) {
        super(message);
    }
    private ExceptionType type;

    // 构造函数，接受异常类型
    public LibraryException(ExceptionType type) {
        super(type.name());
        this.type = type;
    }

    // 获取异常类型
    public ExceptionType getType() {
        return type;
    }

    // 根据异常类型抛出异常的静态方法
    public static void throwException(ExceptionType type) {
        throw new LibraryException(type);
    }

    public void borrowBookWithException(User user, Book book) {
        if (book.getStatus() != BookStatus.AVAILABLE) {
            throw new LibraryException("BOOK_UNAVAILABLE");
        }
        // 其他条件判断同理...
    }
}
